package elitech.vietnam.myfashion.view;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import elitech.vietnam.myfashion.MainActivity;
import elitech.vietnam.myfashion.R;

public class StylerView extends LinearLayout implements View.OnClickListener {

	private MainActivity mContext;
	private LinearLayout mBtnFollow, mBtnStyle, mLayList;
	public AllStyleView mAllStyleView;
	public FollowingStyleView mFollowStyleView;
	private LinearLayout mMainMenu;

	public StylerView(MainActivity context) {
		super(context);
		this.mContext = context;
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if (inflater != null) {
			inflater.inflate(R.layout.styler, this);
		}
		
		this.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
		
		mBtnFollow = (LinearLayout) findViewById(R.id.styler_layBtnFollow);
		mBtnStyle = (LinearLayout) findViewById(R.id.styler_layBtnStyler);
		mLayList = (LinearLayout) findViewById(R.id.styler_layList);
		mMainMenu = (LinearLayout) findViewById(R.id.main_menu);
		mMainMenu.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				mContext.callMenu();
			}
		});
		
		mBtnFollow.setOnClickListener(this);
		mBtnStyle.setOnClickListener(this);
		
		mBtnStyle.setBackgroundColor(Color.TRANSPARENT);
		mBtnFollow.setBackgroundColor(getResources().getColor(R.color.dark_orange));
		
		mAllStyleView = new AllStyleView(mContext);
		mAllStyleView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
		
		mLayList.addView(mAllStyleView);
		
		if (mContext.mUser != null) {
			mFollowStyleView = new FollowingStyleView(mContext);
			mFollowStyleView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
			mBtnFollow.setVisibility(View.VISIBLE);
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.styler_layBtnFollow:
			mBtnFollow.setBackgroundColor(Color.TRANSPARENT);
			mBtnStyle.setBackgroundColor(getResources().getColor(R.color.dark_orange));
			mLayList.removeAllViews();
			mLayList.addView(mFollowStyleView);
			mFollowStyleView.onResume();
			break;
		case R.id.styler_layBtnStyler:
			mBtnStyle.setBackgroundColor(Color.TRANSPARENT);
			mBtnFollow.setBackgroundColor(getResources().getColor(R.color.dark_orange));
			mLayList.removeAllViews();
			mLayList.addView(mAllStyleView);
			break;
		}

	}

	public void onResume() {
		mAllStyleView.onResume();
	}
	
}
